﻿using Newtonsoft.Json;
using PC.PickleJar.Trello.Domain;
using PC.PickleJar.Trello.Data.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
using PC.PickleJar.Trello.Helpers;

namespace PC.PickleJar.Trello.Data
{
	public class CardRepository
	{
		private string developerApiKey;
		private string userToken;

		public CardRepository()
		{
			TrelloConfigurationHelper config = new TrelloConfigurationHelper();
			this.developerApiKey = config.DeveloperApiKey;
			this.userToken = config.UserToken;
		}

		public CardRepository(String developerApiKey, String userToken)
		{
			this.developerApiKey = developerApiKey;
			this.userToken = userToken;
		}

		internal IEnumerable<TrelloCard> GetCardsByBoard(String boardId)
		{
			IEnumerable<TrelloCard> result;

			var client = new TrelloClient<IEnumerable<TrelloCard>>(new CardsByBoardResource(boardId, this.developerApiKey, this.userToken));

			result = client.GetResource().ToList();

			return result;
		}

		public TrelloCard GetCardByShortLink(String cardShortLink)
		{
			TrelloCard result;

			var client = new TrelloClient<TrelloCard>(new CardByShortLinkResource(cardShortLink, this.developerApiKey, this.userToken));

			result = client.GetResource();

			return result;
		}
	}
}
